package com.shunhe.storage.ui.goods;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import androidx.appcompat.widget.AppCompatEditText;

import com.ruitu.arad.base.BaseActivity;
import com.ruitu.arad.util.ToastUtils;
import com.ruitu.router_module.Logg;
import com.ruitu.router_module.util.ViewUtil;
import com.shunhe.storage.R;

// 添加货品
public class AddGoodsActivity extends BaseActivity {
    private CheckBox cb_self_code;// 自编码
    private AppCompatEditText et_fac_name, et_type, et_goods_name, et_goods_code;// 厂家名称,货物分类,货物名称,编码输入框
    private AppCompatEditText et_model, et_pack, et_unit, et_volume, et_weight;// 规格型号,包装,单位,体积,重量
    private TextView tv_save;// 保存

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_add_goods;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        cb_self_code = findViewById(R.id.cb_self_code);
        et_fac_name = findViewById(R.id.et_fac_name);
        et_type = findViewById(R.id.et_type);
        et_goods_name = findViewById(R.id.et_goods_name);
        et_goods_code = findViewById(R.id.et_goods_code);
        et_model = findViewById(R.id.et_model);
        et_pack = findViewById(R.id.et_pack);
        et_unit = findViewById(R.id.et_unit);
        et_volume = findViewById(R.id.et_volume);
        et_weight = findViewById(R.id.et_weight);
        tv_save = findViewById(R.id.tv_save);

        setListeners();

        setHeadTitle("货品添加");

    }

    private void setListeners() {
        setOnClickListener(tv_save);
        cb_self_code.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (cb_self_code.isChecked()) {// 自有编码
                    et_goods_code.setEnabled(true);
                } else {
                    et_goods_code.setEnabled(false);
                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (v == tv_save) {// 保存
            String facName = ViewUtil.getTxt(et_fac_name);
            String type = ViewUtil.getTxt(et_type);
            String goodsName = ViewUtil.getTxt(et_goods_name);
            String code = ViewUtil.getTxt(et_goods_code);
            String model = ViewUtil.getTxt(et_model);
            String pack = ViewUtil.getTxt(et_pack);
            String unit = ViewUtil.getTxt(et_unit);
            String volume = ViewUtil.getTxt(et_volume);
            String weight = ViewUtil.getTxt(et_weight);
            if (TextUtils.isEmpty(facName)) {
                ToastUtils.showShort("请输入厂家名称");
                return;
            }
            if (TextUtils.isEmpty(type)) {
                ToastUtils.showShort("请输入货物分类");
                return;
            }
            if (TextUtils.isEmpty(goodsName)) {
                ToastUtils.showShort("请输入货物名称");
                return;
            }
            if (cb_self_code.isChecked() && TextUtils.isEmpty(code)) {
                ToastUtils.showShort("请输入货物编码");
                return;
            }
            if (TextUtils.isEmpty(model)) {
                ToastUtils.showShort("请输入规格型号");
                return;
            }
            if (TextUtils.isEmpty(pack)) {
                ToastUtils.showShort("请输入包装");
                return;
            }
            if (TextUtils.isEmpty(unit)) {
                ToastUtils.showShort("请输入单位");
                return;
            }
            if (TextUtils.isEmpty(volume)) {
                ToastUtils.showShort("请输入体积");
                return;
            }
            if (TextUtils.isEmpty(weight)) {
                ToastUtils.showShort("请输入重量");
                return;
            }

            String info = facName + type + goodsName + code + model + pack + unit + volume + weight;
            Logg.i("info = " + info);
            ToastUtils.showShort("info = " + info);
        }
    }
}